import React, { useState } from 'react'

// !需求：点击按钮开始倒计时
export default function Test() {
  const [count, setCount] = useState(10)

  const handleClick = () => {
    setInterval(() => {
      // !错误写法，形成了闭包，导致这儿的 count 永远是 10
      // setCount(count - 1)
      setCount((count) => count - 1)
    }, 1000)
  }
  return (
    <div>
      <h3>{count}</h3>
      <button onClick={handleClick}>倒计时</button>
    </div>
  )
}
